﻿using Library.Common.Model;
using Microsoft.AspNetCore.Mvc;
using Synthesize.BaseSet.Domain.Aggregation.Dtos.Authority.Menu;
using Synthesize.BaseSet.ServiceInterface.Dtos.Authority.Menu;
using Synthesize.BaseSet.ServiceInterface.Query.Authority;
using Synthesize.BaseSet.ServiceInterface.UseCase.Authority;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SMS.WebApi.Areas.BaseSet.Controllers
{

    /// <summary>
    /// 菜单功能逻辑接口
    /// </summary>
    public class MenuController : BaseSetBaseController
    {

        private readonly IMenuQueryService _menuQueryService;
        private readonly IMenuService _menuService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public MenuController(IMenuQueryService menuQueryService
            , IMenuService menuService)
        {
            _menuQueryService = menuQueryService;
            _menuService = menuService;
        }

        /// <summary>
        /// 获取用户对应菜单信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<BaseApiResult<GetUserMenuOutput>> GetMenuByUser([FromQuery]GetUserMenuIntput input)
        {
            return await _menuQueryService.GetMenuByUser(input);
        }

        /// <summary>
        /// 获取角色对应菜单信息【所有菜单+可操作标识】
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<BaseApiResult<List<GetMenuTreeByRoleOutput>>> GetMenuTreeByRole([FromQuery]GetMenuTreeByRoleInput input)
        {
            return await _menuQueryService.GetMenuTreeByRole(input);
        }

        /// <summary>
        /// 获取角色对应可操作权限信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<BaseApiResult<List<GetRoleMenuPermissionOutDto>>> GetMenuPermissionListByRole([FromQuery] GetMenuPermissionListByRoleInput input)
        {
            return await _menuQueryService.GetMenuPermissionListByRole(input);
        }

        /// <summary>
        /// 获取菜单树
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<BaseApiResult<List<GetMenuTreeListOutput>>> GetMenuTreeList([FromQuery]GetMenuTreeListInput input)
        {
            return await _menuQueryService.GetMenuTreeList(input);
        }

        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseApiResult<bool>> Create(CreateMenuInput input)
        {
            var res = await _menuService.Create(input);
            return res;
        }

        /// <summary>
        /// 上移菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<BaseApiResult<bool>> UploadMenu(MoveMenuInput input)
        {
            var res = await _menuService.MoveMenu(input);
            return res;
        }

        /// <summary>
        /// 下移菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<BaseApiResult<bool>> DownloadMenu(MoveMenuInput input)
        {
            var res = await _menuService.MoveMenu(input);
            return res;
        }

        

        /// <summary>
        /// 显示或隐藏菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<BaseApiResult<bool>> ForbidOrEnable(ForbidOrEnableInput input)
        {
            return _menuService.ForbidOrEnable(input);
        }

        /// <summary>
        /// 更新菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<BaseApiResult<bool>> Update(UpdateMenuInput input)
        {
            return await _menuService.Update(input); 
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<BaseApiResult<bool>> DeleteById(SingleDeleteInput input)
        {
            return await _menuService.DeleteById(input); 
        }
    }
}
